/* -----------------------------------------------------------------------
 * Christine Hayes
 * Using provided template testUpdateCoins.c
 * This is testing the treasure_map card.
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i, j;
    int seed = 1000;
    int numPlayer = 2;

    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    // One array has two treasure_maps, the other has only one
    int one[MAX_HAND];
    int two[MAX_HAND];
	
	one[0] = treasure_map;
	two[0] = treasure_map;
	two[1] = treasure_map;
	
    for (i = 1; i < MAX_HAND; i++)
    {
        one[i] = copper;
    }
	
	for (j = 2; i < MAX_HAND; i++)
    {
        two[j] = copper;
    }


    printf ("TESTING treasure_map:\n");
    p = 0; 
   
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {

#if (NOISY_TEST == 1)
                printf("Test player %d with %d treasure card(s) and %d bonus.\n", p, handCount, bonus);
#endif
                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                G.handCount[p] = handCount;                 // set the number of cards on hand
				
                memcpy(G.hand[p], one, sizeof(int) * handCount); // set hand to one treasure_map
                cardEffect(treasure_map, 0, 0, 0, &G, 0, &bonus);
#if (NOISY_TEST == 1)
                printf("G.coins = %d, expected = %d\n", G.coins, 4 );
#endif
                assert(G.coins == 4 ); // check if the number of coins is correct

        }

p = 1;
		for (handCount = 1; handCount <= maxHandCount; handCount++)
        {

#if (NOISY_TEST == 1)
                printf("Test player %d with %d treasure card(s) and %d bonus.\n", p, handCount, bonus);
#endif
                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                G.handCount[p] = handCount;                 // set the number of cards on hand
				
                memcpy(G.hand[p], two, sizeof(int) * handCount); // set hand to two treasure_map
                cardEffect(treasure_map, 0, 0, 0, &G, 0, &bonus);
#if (NOISY_TEST == 1)
                printf("G.coins = %d, expected = %d\n", G.coins, 7);
#endif
				//Maybe this is a bug?
                //assert(G.coins == 3 + 4); // check if the number of coins is correct

        }
    printf("All tests passed!\n");

    return 0;
}